package com.semlab.client.widgets;

import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.semlab.client.bundle.Resources;
import com.semlab.client.proxy.ActorProxy;

import java.util.List;

public class PropertyTable extends Container<FlowPanel>{

	private FlexTable table;

	public PropertyTable() {
		super(new FlowPanel());
		render();
	}
	
	protected void render() {
		clear();
	}

	public void insertWidget(Widget key, Widget value){
		int row = table.getRowCount();
		table.setWidget(row, 0, key);
		table.setWidget(row, 1, value);
		table.getFlexCellFormatter().addStyleName(row, 0, Resources.INSTANCE.css().propertyTableKey());
		table.getFlexCellFormatter().addStyleName(row, 1, Resources.INSTANCE.css().propertyTableValue());
	}

	public void insertWidget(String key, String value){
        insertWidget(new Label(key), new Label(value));
	}

	public void insertWidget(String key, Widget value){
		insertWidget(new Label(key), value);
	}

	public TextBox insertTextWidget(String key, String width){
		int row = table.getRowCount();
		TextBox box = new TextBox();
		if(width != null)
			box.setWidth(width);
		box.addStyleName("neo-TextBox");
		table.setWidget(row, 0, new Label(key));
		table.setWidget(row, 1, box);
		table.getFlexCellFormatter().addStyleName(row, 0, "property-Table-Key");
		table.getFlexCellFormatter().addStyleName(row, 1, "property-Table-Value");
		return box;
	}

	public PasswordTextBox insertPasswordWidget(String key){
		int row = table.getRowCount();
		PasswordTextBox box = new PasswordTextBox();
		table.setWidget(row, 0, new Label(key));
		table.setWidget(row, 1, box);
		table.getFlexCellFormatter().addStyleName(row, 0, "property-Table-Key");
		table.getFlexCellFormatter().addStyleName(row, 1, "property-Table-Value");
		return box;
	}

	public void insertButton(Widget p){
		int row = table.getRowCount();
		table.setWidget(row, 1, p);
	}

	@Override
	public void setWidth(String width) {
		table.setWidth(width);
	}


	@Override
	public void setHeight(String height) {
		table.setHeight(height);
	}

    @Override
    public void clear() {
        super.clear();
        table = new FlexTable();
        table.addStyleName("property-Table");
        table.setCellSpacing(0);
        addWidget(table);
    }

}